import request from '@/utils/request'
import API_CONFIG from './config'

// 查询广告列表
export function listAdvertisement(query) {
  const params = {
    ...query,
    orgId: API_CONFIG.ORG_ID
  }
  
  console.log('🔍 [广告API] 调用参数详情:', {
     原始参数: query,
     最终参数: params,
     ORG_ID配置: API_CONFIG.ORG_ID,
     API路径: API_CONFIG.ADVERTISEMENT.LIST
   })
  
  return request({
    url: API_CONFIG.ADVERTISEMENT.LIST,
    method: 'get',
    params: params
  })
}

// 查询广告详细
export function getAdvertisement(adId) {
  return request({
    url: API_CONFIG.ADVERTISEMENT.DETAIL + adId,
    method: 'get',
    params: {
      orgId: API_CONFIG.ORG_ID
    }
  })
}

// 新增广告
export function addAdvertisement(data) {
  const requestData = {
    ...data,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: API_CONFIG.ADVERTISEMENT.ADD,
    method: 'post',
    data: requestData
  })
}

// 修改广告
export function updateAdvertisement(data) {
  const requestData = {
    ...data,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: API_CONFIG.ADVERTISEMENT.UPDATE,
    method: 'put',
    data: requestData
  })
}

// 删除广告
export function delAdvertisement(adId) {
  return request({
    url: API_CONFIG.ADVERTISEMENT.DELETE + adId,
    method: 'delete',
    params: {
      orgId: API_CONFIG.ORG_ID
    }
  })
}